<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>state练习-茅台</title>
    <style>
        .container{
            width: 1062px;
            height: 470px;
            margin: 50px auto;
        }
        .container .left{
            float:left;
        }

        /* .container .left:hover + .right{
            width: 790px;
        } */

        .container .right{
            float:left;
            overflow: hidden;
            width: 0;
            transition: all 0.5s;
        }
        
        .container .show{
            width: 790px;
        }
    </style>
</head>
<body>
    <div id="root"></div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script type="text/babel">
        // jd.com
        class App extends React.Component{
            state = {
                mouseIsIn: false
            }
            //鼠标移入事件
            mouseover = () => {
                this.setState({
                    mouseIsIn: true
                })
            }
            //鼠标离开事件
            mouseout = () => {
                this.setState({
                    mouseIsIn: false
                })
            }

            render(){
                return <div className="container">
                        <div className="left" onMouseOver={this.mouseover} onMouseOut={this.mouseout}>
                            <img src="./images/mt-1.webp" alt="" />    
                        </div>
                        <div className={`right ${this.state.mouseIsIn ? 'show' : ''}`}>
                            <img src="./images/mt-2.webp" alt="" />    
                        </div>
                    </div>
            }
        }

        ReactDOM.render(<App />, document.querySelector("#root"));
    </script>
</body>
</html>